package com.ihr360.payroll.service.payroll;

import com.alibaba.fastjson.JSONObject;
import com.ihr360.commons.request.Ihr360SearchBody;
import com.ihr360.payroll.config.PayrollConfigEntity;
import com.ihr360.payroll.model.dto.salary.meta.PayrollConfig;
import com.ihr360.payroll.model.dto.salary.meta.SalaryField;
import com.ihr360.payroll.model.dto.salary.plan.SalaryPlan;
import com.ihr360.payroll.service.salarytasklet.model.SimplePayrollConfig;
import com.ihr360.rest.service.SimpleRestService;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @author tomtao
 */
public interface PayrollConfigService extends SimpleRestService<PayrollConfig, Long> {

    /**
     * 重新工资表配置为系统配置
     *
     * @param configId
     * @return
     */
    PayrollConfigEntity resetPayrollConfigAsSystem(Long configId);

    /**
     * 获取一个薪资标
     *
     * @param configId
     * @return
     */
    PayrollConfigEntity getOneEntity(Long configId);

    /**
     * 编辑
     *
     * @param configId
     * @return
     */
    PayrollConfig edit(Long configId);

    /**
     * 保存
     *
     * @param payrollConfig
     * @return
     */
    PayrollConfig saveOrUpdate(PayrollConfig payrollConfig);

    /**
     * 保存系统模板
     *
     * @param payrollConfig
     * @return
     */
    PayrollConfig saveOrUpdateSystemTemplate(PayrollConfig payrollConfig);

    /**
     * 获取公司下所有的工资表配置
     *
     * @return
     */
    List<PayrollConfig> list();

    /**
     * 获取工资表中基础输入类别的所有字段
     *
     * @param configId
     * @param categoryId
     * @return
     */
    List<SalaryField> getSalaryFieldByConfigIdAndTypeCategoryId(Long configId, Long categoryId);

    /**
     * 工资表是否被引用
     *
     * @param configId
     * @param haveEnable
     * @return
     */
    boolean isReferenced(Long configId, boolean haveEnable);

    /**
     * 获取帐期内的薪资方案
     *
     * @param companyId
     * @param configId
     * @return
     */
    List<SalaryPlan> getIsPayPeriodSalaryPlanList(String companyId, Long configId);


    SimplePayrollConfig getSimplePayRollConfig(String companyId, Long payrollconfigId);

    List<SalaryField> getProcessedSalaryFieldsWithOutAuth(String companyId, Long payrollconfigId);

    List<SalaryField> getProcessedSalaryFields(String companyId, Long payrollconfigId);

    /**
     * 校验名称是否重复
     *
     * @param name
     * @param configId
     * @return
     */
    boolean isDuplicateName(String name, Long configId);

    /**
     * 校验系统模板名称是否重复
     *
     * @param name
     * @param configId
     * @return
     */
    boolean isDuplicateNameSystemTemplate(String name, Long configId);

    /**
     * 重置公式为系统默认
     *
     * @param id
     * @return
     */
    JSONObject resetFormularToSystem(Long id);

    /**
     * 查询系统模板
     *
     * @param searchBody
     * @return
     */
    Page<PayrollConfig> searchSystemTemplate(Ihr360SearchBody<PayrollConfig> searchBody);

    /**
     * 根据Id 获取系统模板
     *
     * @param id
     * @return
     */
    PayrollConfig getOneSystemTemplate(Long id);

    /**
     * 删除系统模板
     *
     * @param id
     * @return
     */
    boolean deleteSystemTemplateById(Long id);

    /**
     * 删除薪资表
     *
     * @param id
     * @return
     */
    boolean deleteById(Long id);

    /**
     * 获取薪资表，包含系统模板
     *
     * @param id
     * @return
     */
    PayrollConfig getOneContainSystemTemplate(Long id);

    /**
     * 克隆薪资表
     *
     * @param id
     * @return
     */
    PayrollConfig clonePayrollConfig(Long id);

    /**
     * 获取系统模板Id
     *
     * @return
     */
    List<Long> getSystemTemplateIdList();
}